﻿namespace WMS6.Web.Inventory
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.InventoryMgtServiceRef;

    public class ReplenishementGen : BasePage
    {
        protected Button btnGenerate;
        protected Button btnPrint;
        protected DropDownList ddlReplenishmentUom;
        protected HtmlForm F5200;
        protected GridView gvtaskDetail;
        protected Label lblEnd;
        protected Label lblEndOwnerID;
        protected Label lblEndPriority;
        protected Label lblEndSkuID;
        protected Label lblGenerateReplenishmentPage;
        protected Label lblMsg;
        protected Label lblReplenishementNum;
        protected Label lblReplenishmentUom;
        protected Label lblStart;
        protected Label lblStartOwnerID;
        protected Label lblStartPriority;
        protected Label lblStartSkuID;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected ScriptManager ScriptManager1;
        protected TextBox txtEndOwnerID;
        protected TextBox txtEndPriority;
        protected TextBox txtEndSkuID;
        protected TextBox txtReplenishementNum;
        protected TextBox txtStartOwnerID;
        protected TextBox txtStartPriority;
        protected TextBox txtStartSkuID;
        protected UpdatePanel up1;

        protected void btnGenerate_Click(object sender, EventArgs e)
        {
            ReplenishmentGenParamsEntity replenishmentGenParamsEntity = new ReplenishmentGenParamsEntity {
                StartOwnerID = this.txtStartOwnerID.Text,
                EndOwnerID = this.txtEndOwnerID.Text,
                StartSkuID = this.txtStartSkuID.Text,
                EndSkuID = this.txtEndSkuID.Text,
                StartPriority = this.txtStartPriority.Text,
                EndPriority = this.txtEndPriority.Text
            };
            if (!string.IsNullOrEmpty(this.txtReplenishementNum.Text))
            {
                replenishmentGenParamsEntity.ReplenishmentTaskNumber = this.txtReplenishementNum.Text;
            }
            else
            {
                replenishmentGenParamsEntity.ReplenishmentTaskNumber = "100";
            }
            try
            {
                List<TaskDetailInfo> taskDetailList = InventoryMgtServiceClientProxy.GetInstance().GenerateReplenishment(replenishmentGenParamsEntity);
                if (taskDetailList != null)
                {
                    base.BindData2GridView(this.gvtaskDetail, taskDetailList);
                }
                else
                {
                    this.lblMsg.Text = "未找到需要补货的数据源!";
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,2);</script>", false);
            }
        }

        protected void gvtaskDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
            }
        }

        private void LoadData()
        {
            base.BindData2DDLBySysCode(this.ddlReplenishmentUom, "TUOM", true);
            this.ddlReplenishmentUom.Items.Insert(0, "-----");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }
    }
}

